package com.example.design.ddd.practice2.domain.shipping.event;

import com.example.design.ddd.practice2.domain.order.event.OrderPaidEvent;
import com.example.design.ddd.practice2.domain.shipping.entity.Shipping;
import com.example.design.ddd.practice2.domain.shipping.repository.ShippingRepository;
import com.google.common.eventbus.Subscribe;

/**
 * 物流时间监听器(其实就是消费者)
 */
public class ShippingEventHandler {
    private final ShippingRepository shippingRepository;

    public ShippingEventHandler(ShippingRepository shippingRepository) {
        this.shippingRepository = shippingRepository;
    }

    @Subscribe
    public void handleOrderPaid(OrderPaidEvent event) {
        Shipping shipping = Shipping.create(event.getOrderId());
        shippingRepository.save(shipping);
    }
}